{% extends 'base.html' %}
{% load mytags %}
{% block self_head_css_js %}
    <script src="/static/layer/layer.js"></script>
    <script src="/static/js/base.js"></script>
    <script src="/static/plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="/static/plugins/datatables/dataTables.bootstrap.min.js"></script>
    <script src="/static/plugins/datatables/dataTables.bootstrap.css"></script>
{% endblock %}
{% block content %}

    <script>
        window.onload=init;
        function init() {
            var box = document.getElementById("appconf");
            box.className="active";
            var box2 = document.getElementById("project");
            box2.className="active";
        }
    </script>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
    </section>

    <!-- Main content -->
    <section class="content">
        <form action="{% url 'project_del' %}" method="post" id="project_form">
                {% csrf_token %}
            <div class="box">
                <div class="box-header">
                    <div class="btn btn-group" style="padding-left: 0">
						 <a id="projectadd" style="display: none; float:left; margin: auto;" class="btn btn-success" href="{% url 'project_add' %}">添加项目</a>
                         <a id="projectexport" name="export" style="display: none; float:left; margin: auto;" class="btn btn-info search-btn-excel" href="#" onclick="return project_export_excel()">&nbsp;导出&nbsp;</a>
                    </div>
                    <div id="export"></div>
                </div>

                <!-- /.box-header -->
                <div class="box-body">
                  <table class="table table-striped table-bordered" id="projectform">
                      <thead>
                        <tr>
                            <th>
                                <input type="checkbox" onclick="checkAll(this, 'item1');" />
                            </th>
                            <th>项目名称</th>
                            <th>程序类型</th>
                            <th>所属产品线</th>
                            <th>负责人姓名</th>
                            <th>负责人电话</th>
                            <th>操作</th>
                        </tr>
                      </thead>
                            <tbody>
                            {% for project in all_project %}
                                <tr class="even gradeX">
                                    <td><input type="checkbox" id="u_id" class="i-checks" value="{{ project.id }}" name="g_check" /></td>
                                    <td>{{ project.name }} </td>
                                    <td>{{ project.language_type }} </td>
                                    <td>{{ project.product }} </td>
                                    <td>{{ project.owner.name }} </td>
                                    <td>{{ project.owner.phone }} </td>
                                    <td>
                                        <a id="projectedit" style="display: none; float:left; margin: auto;"  href="{% url "project_edit" project.id %}"><span class="btn btn-sm btn-info">编辑</span></a>
                                        <a id="projectdel" style="display: none; float:left; margin: auto;"  href="{% url "project_del"%}?id={{ project.id }}" onclick="return checkSubmit()"><span class="btn btn-sm btn-danger ">删除</span></a>
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                  </table>
                  <div class="btn-group">
                      <button id="projectdel" onclick="return checkSubmit()" style="display: none" class="btn btn-danger" name="delbutton">删除项目</button>
                  </div>
                </div>
            </div>
        </form>
    </section>

</div>
<script>
  $(function () {
    $('#projectform').DataTable({
      "paging": true,
      "lengthChange": true,
      "searching": true,
      "ordering": true,
      "info": true,
      "bAutoWidth": false
    });
  });
</script>
<script>

    function project_export_excel(){
        var project_id_all = getIDall();
        if (project_id_all == ''){
            if(confirm('您没有勾选，是否导出全部信息？')){
                var args = $("#project_form").serialize();
                window.location = "{% url 'project_export' %}?export=all&" + args
            }else{
                return false;
            }
        }else{
            var args = $("#project_form").serialize();
            window.location = "{% url 'project_export' %}?export=part&" + args
        }
    }

</script>
<script>
function checkAll(sender, checkClass) {
    var checkItems = document.getElementsByTagName('input');
    for (var i = 0; i < checkItems.length; i++) {
        var checkItem = checkItems[i];
        if (checkItem.type === 'checkbox' && checkItem.className === 'item1') {
            checkItem.checked = sender.checked;
        }
    }
}
</script>
<script>
function checkSubmit() {
    if (!confirm("确定删除？")) {
        window.event.returnValue = false;
    }
}
</script>
{% endblock %}
